import { getProjects } from '@/api/project'
import { defineStore } from 'pinia'
import type { projectItem } from '@/types/project'
import { ref } from 'vue'
export const useProjectStore = defineStore('project', () => {
  const loading = ref(false)
  const data = ref<projectItem[]>([])
  function setLoading(payload: boolean) {
    loading.value = payload
  }
  function setData(payload: projectItem[]) {
    data.value = payload
  }
  async function fetchProject() {
    if (data.value.length) {
      return
    }
    setLoading(true)
    const resp = await getProjects()
    setData(resp)
    setLoading(false)
  }
  return {
    data,
    loading,
    fetchProject
  }
})
